package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.db.domain.system.PcExpressDelivery;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.service.IPcExpressDeliveryService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 快递公司编码Controller
 * 
 * @author ruoyi
 * @date 2022-08-18
 */
@Api(value = "快递公司编码",tags ="快递公司编码")
@RestController
@RequestMapping("/delivery")
public class PcExpressDeliveryController extends BaseController
{
    private static Logger log = LoggerFactory.getLogger(PcExpressDeliveryController.class);
    @Autowired
    private IPcExpressDeliveryService pcExpressDeliveryService;

    /**
     * 查询快递公司编码列表
     */
    @ApiOperation(value = "查询快递公司编码列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pcExpressDelivery",value="快递公司编码",paramType="form")
    })
    @RequiresPermissions("system:delivery:list")
    @GetMapping("/list")
    public TableDataInfo list(PcExpressDelivery pcExpressDelivery)
    {
        try {
            startPage();
            List<PcExpressDelivery> list = pcExpressDeliveryService.selectPcExpressDeliveryList(pcExpressDelivery);
            return getDataTable(list);
        }catch (Exception e){
            log.error("快递公司编码发生异常",e);
        }
        return null;
    }

    /**
     * 获取快递公司编码详细信息
     */
    @ApiOperation(value = "获取快递公司编码详细信息")
    @ApiImplicitParam(name="id",value="快递公司编码")
    @RequiresPermissions("system:delivery:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        try {
            return AjaxResult.success(pcExpressDeliveryService.selectPcExpressDeliveryById(id));
        }catch (Exception e){
            log.error("快递公司编码发生异常",e);
        }
        return AjaxResult.error("快递公司编码异常");
    }

    /**
     * 新增快递公司编码
     */
    @ApiOperation(value = "新增快递公司编码")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pcExpressDelivery",value="快递公司编码",dataType="PcExpressDelivery")
    })
    @RequiresPermissions("system:delivery:add")
    @Log(title = "快递公司编码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PcExpressDelivery pcExpressDelivery)
    {
        try {
            int i=pcExpressDeliveryService.insertPcExpressDelivery(pcExpressDelivery);
            return toAjax(i);
        }catch (Exception e){
            log.error("新增快递公司编码发生异常",e);
        }
        return AjaxResult.error("快递公司编码异常");
    }

    /**
     * 修改快递公司编码
     */
    @ApiOperation(value = "修改快递公司编码")
    @ApiImplicitParams({
            @ApiImplicitParam(name="pcExpressDelivery",value="快递公司编码",dataType="PcExpressDelivery")
    })
    @RequiresPermissions("system:delivery:edit")
    @Log(title = "快递公司编码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PcExpressDelivery pcExpressDelivery)
    {
        try {
            int i=pcExpressDeliveryService.updatePcExpressDelivery(pcExpressDelivery);
            return toAjax(i);
        }catch (Exception e){
            log.error("修改快递公司编码发生异常",e);
        }
        return AjaxResult.error("快递公司编码异常");
    }

    /**
     * 删除快递公司编码
     */
    @ApiOperation(value = "删除快递公司编码")
    @ApiImplicitParam(name="ids",value="快递公司编码")
    @RequiresPermissions("system:delivery:remove")
    @Log(title = "快递公司编码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        try {
            int i=pcExpressDeliveryService.deletePcExpressDeliveryByIds(ids);
            return toAjax(i);
        }catch (Exception e){
            log.error("删除快递公司编码发生异常",e);
        }
        return AjaxResult.error("快递公司编码异常");
    }
}
